import 'package:city_corner/commons/global-var.dart';
import 'package:city_corner/login-page/login-model.dart';
import 'package:city_corner/login-page/login-form.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPage createState() => _LoginPage();
}

class _LoginPage extends State<LoginPage> {
  bool register = false;

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<LoginModel>(
      create: (context) => LoginModel(),
      child: Builder(builder: (context) {
        return GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () {
              SystemChannels.textInput.invokeMethod('TextInput.hide');
              Provider.of<LoginModel>(context, listen: false).setTop(150);
            },
            child: Container(
                child: Column(
                  children: [
                    Row(
                      children: [
                        GestureDetector(
                          onTap: () => {
                            setState(() {
                              register = !register;
                            })
                          },
                          child: Container(
                              margin: EdgeInsets.only(top: 10),
                              child: Text('注册',
                                  style: TextStyle(
                                      fontSize: 20, color: Colors.grey))),
                        )
                      ],
                      mainAxisAlignment: MainAxisAlignment.end,
                    ),
                    Consumer<LoginModel>(
                      builder: (context, loginModel, child) {
                        return Container(
                          child: LoginForm(register: register),
                          margin: EdgeInsets.only(
                              top: Provider.of<LoginModel>(context).top),
                        );
                      },
                    ),
                  ],
                ),
                margin: EdgeInsets.only(
                    top: topMargin(context), left: 15, right: 15)));
      }),
    );
  }
}
